package com.netease.c.b;

import com.netease.framework.a.h;
import com.netease.framework.a.m;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.ByteArrayEntity;

public class c extends m
{
  public static final int a = 0;
  public static final int b = 1;
  protected static Random c = new Random();
  protected d d;
  protected String e;
  boolean f;
  boolean g;
  int h = 0;

  public c(String paramString, d paramd)
  {
    this(paramString, com.netease.framework.a.b.a, paramd);
  }

  public c(String paramString, com.netease.framework.a.b paramb, d paramd)
  {
    super(paramString, paramb);
    this.d = paramd;
    b("Accept-Encoding", "gzip,deflate");
  }

  protected static String a(String paramString1, String paramString2, List paramList)
  {
    return a.a(paramString1.toUpperCase()) + '&' + a.a(a.d(paramString2)) + '&' + a.a(b(paramList));
  }

  private String a(List paramList)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("OAuth");
    if (1 != this.h)
    {
      String str2 = a.d(super.b());
      if (str2 != null)
      {
        localStringBuilder.append(" realm=\"").append(a.a(str2)).append('"');
        localStringBuilder.append(",");
      }
    }
    LinkedList localLinkedList = new LinkedList();
    for (int i = 0; i < paramList.size(); i++)
    {
      b localb = (b)paramList.get(i);
      String str1 = localb.getName();
      if (!str1.startsWith("oauth_"))
        continue;
      if (i > 0)
        localStringBuilder.append(",");
      localStringBuilder.append(" ");
      localStringBuilder.append(a.a(str1)).append("=\"");
      localStringBuilder.append(a.a(localb.getValue()));
      localStringBuilder.append('"');
      localLinkedList.add(localb);
    }
    paramList.removeAll(localLinkedList);
    return localStringBuilder.toString();
  }

  private static String b(List paramList)
  {
    Collections.sort(paramList);
    StringBuilder localStringBuilder = new StringBuilder();
    Iterator localIterator = paramList.iterator();
    while (localIterator.hasNext())
    {
      b localb = (b)localIterator.next();
      localStringBuilder.append(a.a(localb.getName()));
      localStringBuilder.append("=");
      localStringBuilder.append(a.a(localb.getValue()));
      localStringBuilder.append('&');
    }
    localStringBuilder.deleteCharAt(-1 + localStringBuilder.length());
    return localStringBuilder.toString();
  }

  public void a()
  {
    ArrayList localArrayList = new ArrayList();
    List localList = k();
    if (localList != null)
    {
      Iterator localIterator = localList.iterator();
      while (localIterator.hasNext())
      {
        h localh = (h)localIterator.next();
        localArrayList.add(new b(localh.a(), localh.b()));
      }
    }
    if (this.d.d != null)
      localArrayList.add(new b("oauth_token", this.d.d));
    localArrayList.add(new b("oauth_consumer_key", this.d.a));
    localArrayList.add(new b("oauth_signature_method", this.d.a()));
    localArrayList.add(new b("oauth_version", "1.0"));
    localArrayList.add(new b("oauth_timestamp", String.valueOf(System.currentTimeMillis() / 1000L)));
    localArrayList.add(new b("oauth_nonce", String.valueOf(System.currentTimeMillis() + Math.abs(c.nextLong()))));
    String str1 = a(o().toString(), super.b(), localArrayList);
    localArrayList.add(new b("oauth_signature", this.d.b().a(str1)));
    com.netease.framework.a.b localb = o();
    String str2;
    if ((localb == com.netease.framework.a.b.b) || (localb == com.netease.framework.a.b.d) || (localb == com.netease.framework.a.b.c))
    {
      if ((!this.f) || (p() != null))
        break label424;
      str2 = b(localArrayList);
    }
    while (true)
    {
      try
      {
        byte[] arrayOfByte2 = str2.getBytes("utf-8");
        arrayOfByte1 = arrayOfByte2;
        b("Content-Type", "application/x-www-form-urlencoded");
        a(new ByteArrayEntity(arrayOfByte1));
        localArrayList.clear();
        if (localArrayList.size() <= 0)
          break label452;
        this.e = (super.b() + "?" + URLEncodedUtils.format(localArrayList, "UTF-8"));
        return;
      }
      catch (UnsupportedEncodingException localUnsupportedEncodingException)
      {
        byte[] arrayOfByte1 = str2.getBytes();
        continue;
      }
      label424: if (this.g)
        continue;
      b("Authorization", a(localArrayList));
      localArrayList.clear();
      continue;
      label452: this.e = super.b();
    }
  }

  public void a(int paramInt)
  {
    this.h = paramInt;
  }

  public void a(boolean paramBoolean)
  {
    this.f = paramBoolean;
  }

  public String b()
  {
    return this.e;
  }

  public void b(boolean paramBoolean)
  {
    this.g = paramBoolean;
  }
}

/* Location:           D:\android\hack\dex2jar-0.0.9.8\classes_dex2jar.jar
 * Qualified Name:     com.netease.c.b.c
 * JD-Core Version:    0.6.0
 */